<?php

class FilesController extends Zend_Controller_Action
{

	
    public function init()
    {
    }
    
    public function indexAction()
    {
    	
    	$this->view->title = 'Управление файлами';	
	}

	
	public function getIdtagAction()
    {

		$this->_helper->layout()->disableLayout();
		$this->_helper->viewRenderer->setNoRender();
	    $File = new Files(); 
	    $filename = new zend_session_namespace('filename');
	    $fn =realpath( APPLICATION_PATH . '/..' ) . '/public/mus/' . $filename->file;
	    $return = $File->getIdTags( $fn );
	    echo json_encode( $return );
	   	//echo json_encode($File->getIdTags( $this->filename ) );
    }
    
	public function setIdtagAction()
    {

		$this->_helper->layout()->disableLayout();
		$this->_helper->viewRenderer->setNoRender();
	    $File = new Files(); 
	    $filename = new zend_session_namespace('filename');
	    $fn =realpath( APPLICATION_PATH . '/..' ) . '/public/mus/' . $filename->file;
	    $tag['title'] = $this->_getParam('title');
	    $tag['album'] = $this->_getParam('album');
	    $tag['comment'] = $this->_getParam('comment');
	    $tag['year'] = $this->_getParam('year');
	    $tag['track'] = $this->_getParam('track');
	    $tag['genre'] = $this->_getParam('genre');
	    $tag['artist'] = $this->_getParam('artist');
	    $File->setIdTags( $fn , $tag );
	    $this->_redirect("files");
	    
    }
	
	
	 public function getInfoAction()
    {
			$this->view->title = 'Редактирование файла';

	}
	
	public function getFilesAction()
    {
		$this->_helper->layout()->disableLayout();
    	$this->_helper->viewRenderer->setNoRender();
    	$File = new Files();
    	$allGetFiles = $this->getRequest()->getParam('load');
    	$allId = $this->getRequest()->getParam('id');
    	$File->getFiles( $allGetFiles ,$allId );
    	$this->_redirect('files');
	}
	
	public function downloadAction()
    {
		$this->_helper->layout()->disableLayout();
    	$this->_helper->viewRenderer->setNoRender();
 
    	$Path = $this->getRequest()->getParam('path');
	    $File = new Files();
	    if ( is_file( $Path ) )
	    { 
	    	$File->getFile($Path);
	    }else 
	    $this->_redirect('files');
	   
    }
    
	public function uploadAction()
    {
		$this->_helper->layout()->disableLayout();
    	$this->_helper->viewRenderer->setNoRender();
    	$filename = new zend_session_namespace('filename');
 		$structureDAO = new Files();
    	$pathSrc = $_FILES['upload']['tmp_name'];
    	$pathDest =realpath( APPLICATION_PATH . '/..' ) . '/public/mus';
    	$fileName = $_FILES['upload']['name'];
    	$filename->file = $fileName;
    	if ( $structureDAO->upload($pathSrc, $pathDest, $fileName ) )
    	{
    		echo "true";
    	}else
    	{
    		echo "false";
    	}		
  	$this->_redirect("files/get-info");
  	//echo $filename->file;
    }

	
	



}
